<template>
	<view class="page">
		<!-- 初始提交 -->
		<view class="fw" v-show="gxsj"  @click="editgxsj">用户绑定</view>
		<!-- <view>
			 <u--input
			    placeholder="请输入内容uid"
			    border="surround"
			    v-model="uid"
			  ></u--input>
			<view class="fm2s"><u-button type="primary" @click="dlog()" text="登录"></u-button></view>
		</view> -->
		<!-- 司机预约 -->
		<!-- <sjyuy :uid="uid+''" :sjyuytype="sjyuy" v-if="cdtype==1"></sjyuy> -->
		<!-- 货主 -->
		<!-- <hzdatas  :uid="uid+''"  :hztype="hz"  v-if="cdtype==5"></hzdatas> -->
		<!-- 值班主任 -->
		<!-- <zbzr :uid="uid+''" :zbtype="pzlh"  v-if="cdtype==4"></zbzr> -->
		<!-- 理货员 -->
		<!-- <lhy :uid="uid+''"  :lhtype="lhsj"  v-if="cdtype==3"></lhy> -->
		<!-- 车队管理 --> 
		<!-- <cdgl :uid="uid+''"  :cdtypes="cdyuy"  v-if="cdtype==2"></cdgl> -->
		<component :uid="uid" :types="types" :is="componentId"></component>
		<tabBar :pagePath="'/pages/index/index'"></tabBar>
	</view>
</template>
<script>
	import sjyuy from './@/components/sjyuy/sjyuy.vue'
	import hzdatas from './@/components/hzdatas/hzdatas.vue'
	import zbzr from './@/components/zbzr/zbzr.vue'
	import lhy from './@/components/lhy/lhy.vue'
	import cdgl from './@/components/cdgl/cdgl.vue'
	import newhz from './@/components/newhz/newhz.vue'
	import shy from './@/components/newhz/shy.vue'
	export default {
		data() {
			return {
				uinfo:'',
				uid:'0',
				code:'',
				cdtype:0,
				// appid:'wx544a6c03c80c9eac',	
				appid: "wx92f28e9b99acb503",
				// urls:'https://xstow.hephp.cn',
				urls:'https://szhwx.ypeport.com/index.html',
				componentId:'',
				types:false,
				cjcd:false,
				gxsj:false,
				lhsj:false,
				pzlh:false,
				cdyuy:false,
				hz:false,
				sjyuy:false,
				sjyuy1:false,
				sjyuy2:false,
				lhbbcode:false,
			}
		},
		async onLoad(){
			// let uid = 1906
			// let uid = 2501;
			// let uid = 1656;
			// let uid = 147
			// let uid = 2833;
			let uid = uni.getStoraxwgeSync('uid');
			this.uid = parseInt(uid)
			if(uid==''){
				this.wechatLogin();
			}else{
				this.getuserinfo(uid); 
			}
			// this.getuserinfo(uid); 
		},
		onShow(){
			// let uid = 1906
			// let uid = 147
			// let uid = 2501;
			// let uid = 1656;
			// let uid = 2833;
			let uid = uni.getStorageSync('uid')
			this.uid = parseInt(uid)
			this.getuserinfo(uid);
		},
		methods: {
			tcdl(){
				uni.removeStorageSync('uid');
				uni.removeStorageSync('cdtype');
			},
			//查看车队信息
			getcdsjlist(){
				let cdid = this.uinfo.cdid
				uni.navigateTo({
					url:'/pages/getcdsjlist/getcdsjlist?cdid='+cdid
				})
			},
			//增加司机
			addsiji(){
				let cdid = this.uinfo.cdid
				uni.navigateTo({
					url:'/pages/addsiji/addsiji?cdid='+cdid
				})
			},
			editgxsj(){
				uni.navigateTo({
					url:'/pages/addNews/addNews'
				})
			},
			dlog(){
				console.log('tc')
				uni.removeStorageSync('uid');
				uni.removeStorageSync('cdtype');
				uni.removeStorageSync('udata');
				let uid = this.uid
				uni.setStorageSync('uid', parseInt(uid));
				this.getuserinfo(uid)
				window.location.Reload()
			},
			async getuserinfo(uid){
				let data = {
					id:uid
				}
				let res =  await this.$api.getuserinfo(data)
				if(res.data.code==0){
					this.uid = parseInt(res.data.data.id)
					this.cdtype = res.data.data.cdtype
					uni.setStorageSync('uid', parseInt(res.data.data.id));
					uni.setStorageSync('cdtype', res.data.data.cdtype);
					uni.setStorageSync('udata', res.data.data);
					this.uinfo = res.data.data
					if(res.data.data.status!=1){
						this.types = false
					}else{
						this.types = true
						if(res.data.data.cdtype==1){
							this.gxsj = false
							this.componentId = 'sjyuy'
						}else if(res.data.data.cdtype==2){
							this.gxsj = false
							this.componentId = 'cdgl'
						}else if(res.data.data.cdtype==3){
							this.gxsj = false
							this.componentId = 'lhy'
						}else if(res.data.data.cdtype==4){
							this.gxsj = false
							this.componentId = 'zbzr'
						}else if(res.data.data.cdtype==5){
							this.gxsj = false
							this.componentId = 'hzdatas'
						}else if(res.data.data.cdtype==6){
							this.gxsj = false
							this.componentId = 'newhz'
						}else if(res.data.data.cdtype==7){
							this.gxsj = false
							this.componentId = 'shy'
						}else{
							this.gxsj = true
						}
					}
				}else{
					this.wechatLogin();
				}
			},
			//理货员获取预约理货信息
			async wechatLogin(){
				this.code = this.GetUrlParam('code'); 
				if (!this.code) {
					let uri = encodeURIComponent(window.location.href);
					window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + 
					this.appid +
					"&redirect_uri=" +uri + "&response_type=code&scope=snsapi_userinfo&state=state&wechat_redirect&connect_redirect=1#wechat_redirect";
				}else{
					//设置登录信息
					let res = 	 await this.$api.acctokencode({code:this.code})
					if(res.data.code==0){
						   //进行缓存数据
							uni.setStorageSync('uid', res.data.data.id);
							uni.setStorageSync('cdtype', res.data.data.cdtype);
							uni.setStorageSync('udata', res.data.data);
							console.log(res.data.data)
							this.uid = res.data.data.id
							this.uinfo = res.data.data
							this.cdtype = res.data.data.cdtype
							window.location.href = this.urls;
					}
				}
			},
			GetUrlParam(paraName) {
				//微信回调 回回调当前请求的域名 所以需要从链接后获取参数
					var url = document.location.toString();
					var arrObj = url.split("?");
					if (arrObj.length > 1) {
						var arrPara = arrObj[1].split("&");
						var arr;
						for (var i = 0; i < arrPara.length; i++) {
							arr = arrPara[i].split("=");
							if (arr != null && arr[0] == paraName) {
								return arr[1];
							}
						}
						return "";
					} else {
						return "";
					}
				},
		},
		components:{
			sjyuy,
			hzdatas,
			zbzr,
			lhy,
			cdgl,
			newhz,
			shy
		}
	}
</script>

<style lang="scss" >
	.navsj{
		float: left;
		width: 24%;
		border-right: 1px solid #007AFF;
		text-align: center;
	}
	.fw{
		width: 600upx;
		height: 100upx;
		border: 1upx solid #007AFF;
		text-align: center;
		line-height: 100upx;
		margin: 0 auto;
		margin-top: 30upx;
		font-size: 40upx;
		color: #55aaff;
	}
	.page {
		background-color: #FFFFFF;
		
	}
	.nav{
		 height: 30px;
		 line-height: 30px;
	}
	.navs{
		  height: 60px;
		  line-height: 60px;
		  text-align: center;
		  font-size: 20px;
		  border-right: 1px solid #007AFF;
		  float: left;
		  width: 80px;
	}
	.uni-list-cell {
		justify-content: flex-start
	}
	.loginout{
		border:3px solid #3c77b7;
		color: #ffffff;
		border-radius: 10px;
		margin: 10px auto;
		font-size: 20px;
		height: 60px;
		line-height: 60px;
		width: 80%;
		background-color: #3c77b7;
		text-align: center;
	}
	.mycd{
		padding-left: 20upx;
		font-size: 40upx;
		margin-top: 10upx;
		font-weight: 550;
		color: #55aaff;
		margin-bottom: 40upx;
	}
</style>